
#include "memory/memory.h"
#include "memory_impl.h"

namespace KCore
{
memory* memory_init(memory_type_enum e,size_t size)
{
	switch(e)
	{
	case MemoryFix:
		return new memory_fix(size);
	case MemoryLarge:
		return new memory_large;
	case MemoryDynamic:
		return new memory_dynamic;
	}
	return 0;
}

void memory_clear(memory* p)
{
	memory_dynamic* pD = dynamic_cast<memory_dynamic*>(p);
	if (pD)
	{
		delete pD;
		return;
	}
	memory_large* pL = dynamic_cast<memory_large*>(p);
	if (pL)
	{
		delete pL;
		return;
	}
	memory_fix* pF = dynamic_cast<memory_fix*>(p);
	if (pF)
	{
		delete pF;
		return;
	}
}

void* debug_alloc(size_t sz,memory* p,const char *file,int line)
{
	memory_dynamic* pD = dynamic_cast<memory_dynamic*>(p);
	return pD->debug_alloc(sz,file,line);
}

void debug_free(void* p,memory* pM)
{
	memory_dynamic* pD = dynamic_cast<memory_dynamic*>(pM);
	pD->debug_free(p);
}


};
